package com.smartwebx.ha.dal.realtime.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.smartwebx.ha.dal.config.OracleConfigInfo;
import com.smartwebx.ha.dal.realtime.sqlprovider.RainfallProvider;
import com.smartwebx.ha.dal.usebean.DateValue;
import com.smartwebx.ha.dal.usebean.StatDateValue;
import com.smartwebx.ha.dal.usebean.StationValue;

/**
 * 雨情 dao
 * 
 * @author xx
 * 
 */
@CacheNamespace(size=1024)
public interface RainfallMapper {
	String ST_PSTAT_R = OracleConfigInfo.REALTIME_NAME + ".ST_PSTAT_R";
	String ST_PPTN_R = OracleConfigInfo.REALTIME_NAME + ".ST_PPTN_R";

	/**
	 * 根据时间点(datePoint)与统计时段标志(sttdrcd) 获得统计雨量值
	 * 
	 * @param datePoint
	 *            时间点
	 * @param sttdrcd
	 *            4-->旬；5-->月
	 * @return
	 */
	@Select("SELECT STCD,ACCP val FROM " + ST_PSTAT_R
			+ " WHERE IDTM=#{datePoint} AND STTDRCD=#{sttdrcd}")
	public List<StationValue> getDateSectionTenMonthValStcdFilter(
			@Param("datePoint") Date datePoint, @Param("sttdrcd") int sttdrcd);

	/**
	 * 获得时间段内各个站每日8时的雨量总值
	 * 
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@Select("SELECT STCD,SUM(DYP) val FROM "
			+ ST_PPTN_R
			+ " WHERE TM>=#{startDate} AND TM< #{endDate} AND to_char(TM,'HH24')=8 GROUP BY STCD")
	public List<StationValue> getAllStatDayValStcdFilter(
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 获得各个站点小时时间段内的雨量总值
	 * 
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT STCD,SUM(DRP) val FROM " + ST_PPTN_R
			+ " WHERE TM>=#{startHour} AND TM<#{endHour} GROUP BY STCD")
	public List<StationValue> getAllStatHourValStcdFilter(
			@Param("startHour") Date startHour, @Param("endHour") Date endHour);

	/**
	 * 单站多日日降雨过程
	 * 
	 * @param stcd
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@SelectProvider(type = RainfallProvider.class, method = "getSingleStatMoreDaySQL")
	public List<DateValue> getSingleStatMoreDay(@Param("stcd") String stcd,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 单站单日降雨量
	 * 
	 * @param stcd
	 * @param datePoint
	 * @return
	 */
	@SelectProvider(type = RainfallProvider.class, method = "getSingleStatOneDayValSQL")
	public List<DateValue> getSingleStatOneDayVal(@Param("stcd") String stcd,
			@Param("datePoint") Date datePoint);

	/**
	 * 单站小时降雨量总值
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT SUM(DRP) SUM_DRP FROM " + ST_PPTN_R
			+ " WHERE STCD =#{stcd} AND TM>=#{startHour} AND TM<#{endHour}")
	public Double getNowDateRainVal(@Param("stcd") String stcd,
			@Param("startHour") Date startHour, @Param("endHour") Date endHour);

	/**
	 * 多站多日降雨
	 * 
	 * @param stcds
	 *            多站
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@SelectProvider(type = RainfallProvider.class, method = "getMoreStatMoreDayRainValSQL")
	public List<StatDateValue> getMoreStatMoreDayRainValInQuery(
			@Param("stcds") List<String> stcds,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 多站单日降雨
	 * 注：与原代码不同，需要再次处理参照：getMoreStatOneDayRainfall
	 * @param stcds
	 * @param datePoint
	 * @return
	 */
	@SelectProvider(type = RainfallProvider.class, method = "getMoreStatOneDayRainValSQL")
	public List<StatDateValue> getMoreStatOneDayRainValInQuery(
			@Param("stcds") List<String> stcds,
			@Param("datePoint") Date datePoint);

	/**
	 * 多站当日小时合计雨量
	 * 
	 * @param astcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT STCD,SUM(DRP) val FROM "
			+ ST_PPTN_R
			+ " WHERE TM>=#{startHour} AND TM<#{endHour} AND STCD IN (#{stcds,typeHandler=InQueryHandler}) GROUP BY STCD")
	public List<StationValue> getMoreStatHourTotalRainValInQuery(
			@Param("stcds") List<String> stcds,
			@Param("startHour") Date startHour, @Param("endHour") Date endHour);

	/**
	 * 多站当日小时雨量
	 * 
	 * @param stcds
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT STCD,DRP val,TM FROM "
			+ ST_PPTN_R	
			+ " WHERE TM>=#{startHour} AND TM<#{endHour} AND DRP IS NOT NULL AND STCD IN (#{stcds,typeHandler=InQueryHandler})")
	public List<StatDateValue> getMoreStatHourRainValInQuery(
			@Param("stcds") List<String> stcds,
			@Param("startHour") Date startHour, @Param("endHour") Date endHour);

	/**
	 * 单站小时雨量
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT DRP val,TM FROM " + ST_PPTN_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startHour} AND TM<#{endHour}")
	public List<DateValue> getSingleStatMoreHour(@Param("stcd") String stcd,
			@Param("startHour") Date startHour, @Param("endHour") Date endHour);

}
